package org.yzh.codec;

import io.github.yezhihao.protostar.FieldFactory;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import org.yzh.protocol.basics.JTMessage;
import org.yzh.protocol.codec.JTMessageDecoder;

/**
 * 解码分析
 * @author yezhihao
 * @home https://gitee.com/yezhihao/jt808-server
 */
public class Elucidator {

    public static final JTMessageDecoder decoder;

    static {
        FieldFactory.EXPLAIN = true;
        decoder = new JTMessageDecoder("org.yzh.protocol");
    }

    public static void main(String[] args) {
        //String hex = "020000d40123456789017fff000004000000080006eeb6ad02633df7013800030063200707192359642f000000400101020a0a02010a1e00640001b2070003640e200707192359000100000061646173200827111111010101652f000000410202020a0000000a1e00c8000516150006c81c20070719235900020000000064736d200827111111020202662900000042031e012c00087a23000a2c2a200707192359000300000074706d732008271111110303030067290000004304041e0190000bde31000d90382007071923590004000000006273642008271111110404049d";
        // String hex = "7E0100002108888069681700040000000037303935394A53362D410000003036393638313702CBD5413132333435187E";
        //String hex = "7E120523860040200004590AA100050001031800000090012107260313312107260358300000000000000000020101175F39FE0221072603133121072603583000000000000000000201011BD890280321072603133121072603583000000000000000000201010338BBC204210726031331210726035830000000000000000002010115D2EE6C0521072603133121072603583000000000000000000201011BFD8FEC06210726031331210726035830000000000000000002010103372F20072107260313312107260358300000000000000000020101033C0C92082107260313312107260358300000000000000000020101033F0FF0012107260358312107260442560000000000000000020101187D024C7C0221072603583121072604425600000000000000000201011B93077A0321072603583121072604425600000000000000000201010335E63C0421072603583121072604425600000000000000000201011677E6C20521072603583121072604425600000000000000000201011BB1D76A06210726035831210726044256000000000000000002010103390938072107260358312107260442560000000000000000020101032D715408210726035831210726044256000000000000000002010103322A2001210726044257210726045556000000000000000002010107CDD95402210726044257210726045556000000000000000002010108005F4603210726044257210726045556000000000000000002010100F49D2A042107260442572107260455560000000000000000020101075954EA0521072604425721072604555600000000000000000201010820E8D206210726044257210726045556000000000000000002010100F8030407210726044257210726045556000000000000000002010100F51FAA08210726044257210726045556000000000000000002010100F71552012107260456412107260541400000000000000000020101194101B20221072604564121072605414000000000000000000201011BC6717203210726045641210726054140000000000000000002010103576DE404210726045641210726054140000000000000000002010114B90C180521072604564121072605414000000000000000000201011C0A518E0621072604564121072605414000000000000000000201010359A7F607210726045641210726054140000000000000000002010103582F4808210726045641210726054140000000000000000002010103589EF0D07E";

        //String hex = "7E120523800040200004590AA200050002012107260541412107260626400000000000000000020101195C0E180221072605414121072606264000000000000000000201011B3C470E032107260541412107260626400000000000000000020101032A7F3A0421072605414121072606264000000000000000000201011867235E0521072605414121072606264000000000000000000201011C073968062107260541412107260626400000000000000000020101033058DC072107260541412107260626400000000000000000020101033149F2082107260541412107260626400000000000000000020101032F4E980121072606264121072607114000000000000000000201011395B96E0221072606264121072607114000000000000000000201011BEB292C032107260626412107260711400000000000000000020101033BD00C0421072606264121072607114000000000000000000201011625AFE60521072606264121072607114000000000000000000201011C0327F8062107260626412107260711400000000000000000020101034453D2072107260626412107260711400000000000000000020101034224C20821072606264121072607114000000000000000000201010346C636012107260711412107260756400000000000000000020101160766600221072607114121072607564000000000000000000201011BDDDD76032107260711412107260756400000000000000000020101034D6F4A04210726071141210726075640000000000000000002010119FD08BA0521072607114121072607564000000000000000000201011BF2E6020621072607114121072607564000000000000000000201010351EA080721072607114121072607564000000000000000000201010350C432082107260711412107260756400000000000000000020101034EA57C0121072607564121072608414000000000000000000201011066CE160221072607564121072608414000000000000000000201011BCFFF900321072607564121072608414000000000000000000201010328295C04210726075641210726084140000000000000000002010119745B2E0521072607564121072608414000000000000000000201011C2811300621072607564121072608414000000000000000000201010324D3BA07210726075641210726084140000000000000000002010103293B900821072607564121072608414000000000000000000201010325730AC87E";

        String hex = "7e80010005013459461831000e02850002000c7e";

        JTMessage message = decoder.decode(Unpooled.wrappedBuffer(ByteBufUtil.decodeHexDump(hex)));
        System.out.println();
        System.out.println(hex);
        System.out.println(message);
    }
}